<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发送 POST 请求</title>
    <style>
        div{
            width: 400px;
            height: 400px;
            border:solid 1px #000;
        }
    </style>
</head>
<body>
    <div></div>
    <script>
       window.onload = function(){

            // 1. 创建一个ajax对象
            let xhr = new XMLHttpRequest();

            // 2. open
            xhr.open("post","http://127.0.0.1/getUser");

            // 3. send
            xhr.send();

            // 4. 监听事件
            xhr.onreadystatechange = function(){
                // 响应完成 && 状态成功
                if(xhr.readyState === 4 && xhr.status === 200){
                    // console.log(xhr.response);

                    document.querySelector('div').innerHTML = xhr.response;
                }
            }    
       }

    </script>
</body>
</html>